#include "buttonform.h"
#include "ui_buttonform.h"


//自定义按钮
ButtonForm::ButtonForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ButtonForm)
{
    ui->setupUi(this);

    ui->btBox->hide();//隐藏音符

    setLineStyle();//设置音符的跳动效果
}

ButtonForm::~ButtonForm()
{
    delete ui;
}

int ButtonForm::getID() const
{
    return PageID;
}

void ButtonForm::clearStyle()
{
    ui->btStyle->setStyleSheet("#btStyle:hover{background-color:#D8D8D8;}");
}

void ButtonForm::setIconAndText(const QString &Icon, const QString &Text,int PageID)
{
    ui->btIcon->setPixmap(QPixmap(Icon));
    ui->btText->setText(Text);

    this->PageID=PageID;
}

void ButtonForm::showLineStyle()
{
    ui->btBox->show();
}

void ButtonForm::setLineStyle()
{
    //按钮中的每个line设置跳动的动画效果
    line1Action=new QPropertyAnimation(ui->line1,"geometry",this);
    line1Action->setDuration(1500);//1500毫秒 4 0 3 20
    //设置关键帧
    line1Action->setKeyValueAt(0,QRect(2,20,3,2));
    line1Action->setKeyValueAt(0.5,QRect(2,0,3,20));
    line1Action->setKeyValueAt(1,QRect(2,20,3,2));
    line1Action->setLoopCount(-1);
    line1Action->start();

    line2Action=new QPropertyAnimation(ui->line2,"geometry",this);
    line2Action->setDuration(1600);//1500毫秒 16 0 3 20
    line2Action->setKeyValueAt(0,QRect(9,20,3,2));
    line2Action->setKeyValueAt(0.5,QRect(9,0,3,20));
    line2Action->setKeyValueAt(1,QRect(9,20,3,2));
    line2Action->setLoopCount(-1);
    line2Action->start();

    line3Action=new QPropertyAnimation(ui->line3,"geometry",this);
    line3Action->setDuration(1700);//1500毫秒 28 0 3 20
    line3Action->setKeyValueAt(0,QRect(16,20,3,2));
    line3Action->setKeyValueAt(0.5,QRect(16,0,3,20));
    line3Action->setKeyValueAt(1,QRect(16,20,3,2));
    line3Action->setLoopCount(-1);
    line3Action->start();

    line4Action=new QPropertyAnimation(ui->line4,"geometry",this);
    line4Action->setDuration(1800);//1500毫秒 40 0 3 20
    line4Action->setKeyValueAt(0,QRect(23,20,3,2));
    line4Action->setKeyValueAt(0.5,QRect(23,0,3,20));
    line4Action->setKeyValueAt(1,QRect(20,23,3,2));
    line4Action->setLoopCount(-1);
    line4Action->start();
}

void ButtonForm::setLocalStyle()
{
    ui->btStyle->setStyleSheet("#btStyle{background-color:rgb(30,206,154);}");
    setLineStyle();//设置音符的跳动效果
}

void ButtonForm::mousePressEvent(QMouseEvent *event)
{
    (void)event;
    //1,鼠标按下后，将颜色先修改
    ui->btStyle->setStyleSheet("#btStyle{background-color:rgb(30,206,154);}");

    //2,再显示对应的page页面
    //实现页面的切换，通过信号槽机制
    //ButtonForm被点击后，发送一个信号，带上pageID
    //music捕捉这个信号,根据pageID决定要切换哪个page
    emit btClick(PageID);
}
